package servlet.InterFace;

import org.json.JSONArray;
import service.SearchService;
import service.SearchServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "InterFace2", value = "/InterFace2")
public class InterFace2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json; charset=utf-8");
        String bikeName = request.getParameter("bike_name");
        PrintWriter out = response.getWriter();
        SearchService searchService = new SearchServiceImpl();
        JSONArray jsonArray = searchService.searchToDisplay(bikeName);
        if(jsonArray!=null){
            if(jsonArray.isEmpty())
            {
                out.println("无数据");
                return;
            }
            out.println(jsonArray);

        }else {
            out.println("系统内部出现错误");
        }
    }
}
